<template>
  <div class="site-wrapper site-page--login">
    <div class="site-content__wrapper">




        <div class="login-main" v-if="visible">


        <div class="log-title">
                <span>银政通<font color="red">测试系统</font></span>
        </div>

          <h3 class="login-title">用户登录</h3>
          <el-form :model="dataForm"  :rules="dataRule" ref="dataForm" @keyup.enter.native="useVerify()" status-icon>
            <el-form-item prop="orgcode">
              <el-input v-model="dataForm.orgcode" placeholder="机构号" clearable></el-input>
            </el-form-item>

            <el-form-item prop="userName">
              <el-input v-model="dataForm.userName" placeholder="帐号" clearable ></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="dataForm.password" type="password" placeholder="密码" clearable ></el-input>
            </el-form-item>

            <el-form-item>
              <el-button class="login-btn-submit" type="primary" @click="useVerify()">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <Verify
            @success="success"
            :mode="'pop'"    
            :captchaType="captchaType"   
                :imgSize="{ width: '330px', height: '155px' }" 
                ref="verify"
            ></Verify>
        </div>
      </div>
    </div>
  
</template>

<script>

  import screenfull from "screenfull";
  import Verify from "./../../components/verifition/Verify";  
  export default {
    data () {

      return {
        visible: true,
        captchaType: 'blockPuzzle',
        dataForm: {
          orgcode: '',
          userName: '',
          password: '',
          uuid: '',
          captcha: ''
        },
        dataRule: {

          userName: [
            { required: true, message: '帐号不能为空', trigger: 'blur' }
          ],

          password: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ],
          captcha: [
            { required: true, message: '验证码不能为空', trigger: 'blur' }
          ]
        },
        captchaPath: ''
      }
    },
    components: {
		  Verify
	  },
    created () {
      this.getCaptchaType()
      this.dataForm.userName = ''
    },
    mounted () {
      this.dataForm.userName = ''
      window.addEventListener("keydown", this.KeyDown, true)// 监听按键事件
    },
    methods: {
     KeyDown (event) {
          if (event.keyCode === 122) {
            event.returnValue = false
            this.isScreenFull();                    
          }
      },
      isScreenFull() {
         if (!screenfull.isEnabled) {
            // 如果不支持进入全屏，发出不支持提示
            this.$message({
              message: "您的浏览器版本过低不支持全屏显示！",
              type: "warning"
            });
            return false;
        }
        screenfull.toggle();
      },
      // 提交表单
      dataFormSubmit (params) {
            this.$http({
              url: this.$http.adornUrl('/sys/login'),
              method: 'post',
              data: this.$http.adornData({
                'orgcode': this.dataForm.orgcode,
                'username': this.dataForm.orgcode != '' ? 
                    this.dataForm.userName+"#" + this.dataForm.orgcode : this.dataForm.userName,
                'password': this.dataForm.password,
                'uuid': this.dataForm.uuid,
                'captcha': params ? params.captchaVerification : ""
              })
            }).then(({data}) => {
              if (data && data.code === 0) { 
                  this.dataForm.orgcode = ''     
                  this.visible = false         
                  this.$cookie.set('token', data.token)
                  this.$router.replace({ name: 'home' })              

              } else {

                this.$message.error(data.msg)
              }
            })
          
      },
      getCaptchaType () {
        this.$http({
              url: this.$http.adornUrl(`/captcha/type`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.captchaType = data.captchaType
              }
            })

      },
      success(params){
        this.dataFormSubmit(params)
      },
      useVerify(){           
      this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.captchaType == 'off'){
                this.dataFormSubmit()
            }else{
                this.$refs.verify.show()   
            }
                       
          }
        })
      },


    }
  }
</script>

<style lang="scss">

.log-title {
    position: relative;
    left: 6px;
    top: -104px;
    font-family: "SimHei";
    font-size: 46px;
    color: #ffffff;
}

  .site-wrapper.site-page--login {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba(38, 50, 56, .6);
    overflow: hidden;
    &:before {
      position: fixed;
      top: 0;
      left: 0;
      z-index: -1;
      width: 100%;
      height: 100%;
      content: "";
      background-image: url(~@/assets/img/login-bg.png);
      background-size: cover;
    }
    .site-content__wrapper {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      padding: 0;
      margin: 0;
      overflow-x: hidden;
      overflow-y: auto;
      background-color: transparent;
    }
    .site-content {
      min-height: 100%;
      padding: 30px 500px 30px 30px;
    }
    .brand-info {
      margin: 220px 100px 0 90px;
      color: #fff;
    }
    .brand-info__text {
      margin:  0 0 22px 0;
      font-size: 48px;
      font-weight: 400;
      text-transform : uppercase;
    }
    .brand-info__intro {
      margin: 10px 0;
      font-size: 16px;
      line-height: 1.58;
      opacity: .6;
    }

// .login-main{margin:0 auto;border:1px solid #000;width:300px;height:100px} 

  .login-main {
      margin:0 auto;
      padding: 10px 60px 50px;
      margin-top:220px;
      width: 470px;
      height: 320px;
      background-color: rgb(170, 183, 196);
    }

    // .login-main {
    //   position: absolute;
    //   top: 200px;
    //   right:500px;
    //   padding: 10px 60px 50px;
     
    //   width: 470px;
    //   height: 400px;
    //   background-color: rgb(170, 183, 196);
    // }
    .login-title {
      font-size: 16px;
      margin-top:-20px;
    }
    .login-captcha {
      overflow: hidden;
      > img {
        width: 100%;
        cursor: pointer;
      }
    }
    .login-btn-submit {
      width: 100%;
      margin-top: 0px;
    }
  }
</style>
